'use strict'
module.exports = (app) => {
  const { STRING, INTEGER, DATE } = app.Sequelize
  // 配置（重要：一定要配置详细，一定要！！！）
  const Wall = app.model.define('wall', {
    id: {
      type: INTEGER(20).UNSIGNED,
      primaryKey: true,
      autoIncrement: true
    },
    title: {
      type: STRING(20),
      allowNull: false,
      comment: '标题'
    },
    slogan: {
      type: STRING(200),
      allowNull: false,
      comment: '标语'
    },
    created_time: {
      type: DATE,
      get() {
        return app.formatTime(this.getDataValue('created_time'))
      }
    }
  })
  // 关联关系
  Wall.associate = (models) => {
    // 一对多
    Wall.hasMany(app.model.Label, {
      foreignKey: 'wall_id',
      as: 'labels'
    })
    Wall.hasMany(app.model.Color, {
      foreignKey: 'wall_id',
      as: 'colors'
    })
  }
  return Wall
}
